package com.poker.wiki.controller;


import com.github.pagehelper.PageInfo;
import com.poker.common.utils.Result;
import org.springframework.web.bind.annotation.*;
import com.poker.wiki.Service.EbookService;
import com.poker.wiki.entity.Ebook;
import com.poker.wiki.req.EbookQueryReq;
import com.poker.wiki.req.EbookSaveReq;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("")
public class EbookController {

    @Resource
    EbookService ebookService;

    @RequestMapping("getAllEbook")
    public Result getAllEbook(@Valid EbookQueryReq req) {
//        if ( pageNum == null || pageSize == null){
//            pageNum = 1;
//            pageSize = 2;
//        }
//        PageHelper.startPage(pageNum, pageSize);
//        List<Ebook> ebookList = ebookService.getAllEbook();
//        PageInfo<Ebook> pageInfo = new PageInfo<>(ebookList);

        PageInfo<Ebook> pageInfo = ebookService.getAllEbook(req);

        return Result.success(pageInfo);
    }

    @PostMapping("/saveEbook")
    public Result save(@RequestBody @Valid EbookSaveReq req){
        ebookService.save(req);
        return Result.success();
    }

    @DeleteMapping("/deleteEbook/{id}")
    public Result delete(@PathVariable Long id){
        ebookService.delete(id);
        return Result.success();
    }
}
